package com.duolaibei.business.utils;

import android.content.Context;

import com.duolaibei.business.R;
import com.duolaibei.business.model.OrderBeanData;
import com.duolaibei.business.model.OrderListData;
import com.duolaibei.business.utils.print.ESCUtil;

/**
 * Created by xlm on 2017/11/15 0015
 */

public class DlbPrintUtil {
    /**
     * 打印小票list
     */
    public static void printListData(Context context, OrderListData.DataBeanX.DataBean dataBean
            , String content, int printCount) {
        if (BluetoothUtil.connectBlueTooth(context)) {
            //打印
            PrintUtils.setOutputStream(BluetoothUtil.getOutputStream());
            for (int i = 0; i < printCount; i++) {
                PrintUtils.selectCommand(PrintUtils.RESET);
                PrintUtils.selectCommand(PrintUtils.LINE_SPACING_DEFAULT);
                PrintUtils.selectCommand(PrintUtils.ALIGN_LEFT);
                PrintUtils.printText("商户名：" + dataBean.getBody() + "\n");
                PrintUtils.printText("--------------------------------\n");
                PrintUtils.printText("订单金额：" + dataBean.getTotal_amount() + "\n");
                PrintUtils.printText("交易金额：" + dataBean.getPay_amount() + "\n");

                PrintUtils.printText("支付类型：" + dataBean.getPay_name() + "\n");
                PrintUtils.printText("备注信息：" + dataBean.getRemark() + "\n");
                PrintUtils.printText(String.format(context.getString(R.string._6_s),
                        CommonUtil.formatDate(Long.valueOf(dataBean.getPaytime()) * 1000,
                                "yyyy-MM-dd HH:mm:ss")) + "\n");
                PrintUtils.printText("订单号：" + dataBean.getOut_trade_no() + "\n");
//              content = content.substring(4, content.length());
//              content = content.substring(0, content.length() - 1);
//              PrintUtils.printBitmap(PrintUtils.getPrintBarCode(content, 8, 65, 2, 0));
//                PrintUtils.printBitmap(ESCUtil.getPrintQRCode(content, 5, 2));
                PrintUtils.printBitmap(ESCUtil.getPrintQRCode2(content, 230));
                PrintUtils.printText("--------------------------------\n");
                PrintUtils.printText("多来贝商家技术服务：" + "400-071-5877");
                PrintUtils.printText("\n\n\n\n\n");
            }
        }
    }

    /**
     * 打印小票
     */
    public static void printData(Context context, OrderBeanData.DataBean dataBean,
                                 String content, int printCount) {
        if (BluetoothUtil.connectBlueTooth(context)) {
            //打印
            PrintUtils.setOutputStream(BluetoothUtil.getOutputStream());
            for (int i = 0; i < printCount; i++) {
                PrintUtils.selectCommand(PrintUtils.RESET);
                PrintUtils.selectCommand(PrintUtils.LINE_SPACING_DEFAULT);
                PrintUtils.selectCommand(PrintUtils.ALIGN_LEFT);
                PrintUtils.printText("商户名：" + dataBean.getBody() + "\n");
                PrintUtils.printText("--------------------------------\n");
                PrintUtils.printText("订单金额：" + dataBean.getTotal_amount() + "\n");
                PrintUtils.printText("交易金额：" + dataBean.getPay_amount() + "\n");

                PrintUtils.printText("支付类型：" + dataBean.getPay_name() + "\n");
                PrintUtils.printText("备注信息：" + dataBean.getRemark() + "\n");
                PrintUtils.printText(String.format(context.getString(R.string._6_s),
                        CommonUtil.formatDate(Long.valueOf(dataBean.getPaytime()) * 1000,
                                "yyyy-MM-dd HH:mm:ss")) + "\n");
                PrintUtils.printText("订单号：" + dataBean.getOut_trade_no() + "\n");
//              content = content.substring(4, content.length());
//              content = content.substring(0, content.length() - 1);
//              PrintUtils.printBitmap(PrintUtils.getPrintBarCode(content, 8, 65, 2, 0));
//                PrintUtils.printBitmap(ESCUtil.getPrintQRCode(content, 5, 2));
                PrintUtils.printBitmap(ESCUtil.getPrintQRCode2(content, 230));
                PrintUtils.printText("--------------------------------\n");
                PrintUtils.printText("多来贝商家技术服务：" + "400-071-5877");
                PrintUtils.printText("\n\n\n\n\n");
            }
        }
    }

}
